<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>EQEmu</title>
    <link rel="stylesheet" type="text/css" href="style/style.css"/>
    <script src="scripts/jquery.js"></script>
    <script>
    <!--
    var idx = Math.floor((Math.random()*100000000));
    function GetStatusIdx() {
        return idx++;
    }

    function StatusTic() {
        $.getJSON("data/zone_data.html?idx="+GetStatusIdx(),
            function(data) {
                var elm = document.getElementById('zone_count');
                elm.innerHTML = data.zone_count;

                $("#zone_table").empty();
                var app_html = "<tr>";
                app_html += "<th scope=\"col\">Zone Name </th>";
                app_html += "<th scope=\"col\">Instance Id</th>";
                app_html += "<th scope=\"col\">Players</th>";
                app_html += "</tr>";
                $("#zone_table").append(app_html);

                var i = 0;
                for(var i = 0; i < data.zone_count; i++) {
                    app_html = "<tr>";
                    if(data.zones[i].type == "dynamic") {
                        if(data.zones[i].zone_id == 0) {
                            app_html += "<td><b>"+data.zones[i].launch_name+":</b> Idle</td>";
                        } else {
                            app_html += "<td><b>"+data.zones[i].launch_name+":</b> "+data.zones[i].long_name+"("+data.zones[i].short_name+")"+"</td>";
                        }
                    } else {
                        app_html += "<td>" + data.zones[i].long_name + " (" + data.zones[i].short_name + ")</td>";
                    }

                    app_html += "<td>" + data.zones[i].instance_id + "</td>";
                    app_html += "<td><a href='playerview.html?zone=" + data.zones[i].short_name + "&instance=" + data.zones[i].instance_id + "'>Players</a></td>";
                    app_html += "</tr>";

                    $("#zone_table").append(app_html);
                }
            });
    }

    $(document).ready(function() {
        setInterval("StatusTic()", 4000);
    });
    -->
    </script>
</head>
<?

  @zones = $EQW->ListBootedZones();
#  @zones = (
#   { type => "dynamic", short_name => "arena", long_name => "Arena", port => 8001 },
#   { type => "static", short_name => "freportw", long_name => "West Freeport", port => 8002 },
#   { type => "static", short_name => "freportn", long_name => "North Freeport", port => 8003 }
#  );

?>
<body>
    <div class="container">
        <?do("templates/scripts/menu_noaccess.pl");?>
        <div id="main_content" class="main">
            <h2 align="center">Zone List</h2>
            <?
            print "You have <span id='zone_count'>".($#zones+1)."</span> zones running.";
            ?>
            <table id='zone_table' class='styled_table' width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <th scope="col">Zone Name </th>
                <th scope="col">Instance Id</th>
                <th scope="col">Players</th>
              </tr>
            <?
              for my $zonekey (sort @zones) {
                    my $zone = $EQW->GetZoneDetails($zonekey);
                    if(!$zone) {
                        $zone->{long_name} = "ERROR: no zone";
                    } elsif($zone->{error}) {
                        $zone->{long_name} = "ERROR: $zone->{error}";
                    }

                    print "<tr>\n";
                    if($zone->{type} eq "dynamic") {
                        if($zone->{zone_id} == 0) {
                            print "\t<td><b>$zone->{launch_name}:</b> Idle</td>";
                        } else {
                            print "\t<td><b>$zone->{launch_name}:</b> $zone->{long_name} ($zone->{short_name})</td>";
                        }
                    } else {
                        print "<td>$zone->{long_name} ($zone->{short_name})</td>";
                    }
                    print "<td>$zone->{instance_id}</td>";
                    print "<td><a href='playerview.html?zone=$zone->{short_name}&instance=$zone->{instance_id}'>Players</a></td>";
                    print "</tr>\n";
              }
            ?>
            </table>
        </div>
    </div>
    <div class="footer">
        &copy 2012 EQEmu. All rights reserved.
    </div>
</body>
</html>
